namespace ETestIT.Web.Presentation.State
{
    using System.Web;
    using System.Web.SessionState;
    using Controllers.Extensions;

    public class AppState : IAppState
    {
        private readonly HttpSessionState Session;

        public AppState()
        {
            Session = HttpContext.Current.Session;
        }

        public T Get<T>(string key)
        {
            if (Session[key] == null)
                return default(T);

            return (T)Session[key];
        }

        public void Set<T>(string key, T value)
        {
            Session[key] = value;
        }

        public T Get<T>()
        {
            return Get<T>(typeof(T).Name);
        }

        public void Set<T>(T val)
        {
            Set(typeof(T).Name, val);
        }

        public string GetString(string key)
        {
            var s = Get<string>(key);
            return s ?? string.Empty;
        }

        public void SetString(string key, string value)
        {
            Set(key, value);
        }
    }

}